<?php

class ScriptAlone_Store_KeyValue_Memcache extends ScriptAlone_Store_KeyValue {

	/** @var Memcache */
	protected $memcache;

	public function __construct($key, $serverHost = 'localhost', $serverPort = 11211) {
		$this->memcache = new Memcache();
		if(!$this->memcache->connect($serverHost, $serverPort)) {
			throw new Exception('Unable to connect to Memcache server on ' . $serverHost . ':' . $serverPort);
		}
	}

	protected function get($key) {
		return $this->memcache->get($key);
	}

	protected function set($key, $dataString) {
		$this->memcache->set($key, $dataString);
	}

	protected function delete($key) {
		$this->memcache->delete($key);
	}
}
